<?php
Loader::loadClass('ObjectUtilEx', "modules/VoteCanvasser/pnincludes");
Loader::loadClass('DateUtilEx', "modules/VoteCanvasser/pnincludes");
Loader::loadClass('PNObjectEx', "modules/VoteCanvasser/pnincludes");
Loader::loadClass('PNObjectExArray', "modules/VoteCanvasser/pnincludes");
Loader::loadClass('DBUtilEx', "modules/VoteCanvasser/pnincludes");
Loader::loadClass('InnoUtil', "modules/VoteCanvasser/pnincludes");

function VoteCanvasser_pntables()
{
    // Initialise table array
    $pntable = array();

    ////////////////////////////////////////////
    //Canvasser type table
    ////////////////////////////////////////////
    $pntable['votecanvasser_type'] = DBUtil::getLimitedTablename('votecanvasser_type');
    $pntable['votecanvasser_type_column'] = array(
                                        'id'                => 'typ_id',
                                        'name'              => 'typ_name'
    );
    $pntable['votecanvasser_type_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'name'              => 'varchar(255)'
    );
    $pntable['votecanvasser_type_primary_key_column'] = 'id';

    //Add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition($pntable['votecanvasser_type_column'], 'typ_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['votecanvasser_type_column_def']);


    ////////////////////////////////////////////
    //House no. table
    ////////////////////////////////////////////
    $pntable['votecanvasser_house_no'] = DBUtil::getLimitedTablename('votecanvasser_house_no');
    $pntable['votecanvasser_house_no_column'] = array(
                                        'id'                => 'hou_id',
                                        'pro_id'            => 'hou_pro_id',
                                        'dis_id'            => 'hou_dis_id',
                                        'tam_id'            => 'hou_tam_id',
                                        'vil_id'            => 'hou_vil_id',
                                        'vil_moo'           => 'hou_vil_moo',
                                        'no'                => 'hou_no',
                                        'unit'              => 'hou_unit',
                                        'trok'              => 'hou_trok',
                                        'soi'               => 'hou_soi',
                                        'road'              => 'hou_road',
                                        'zipcode'           => 'hou_zipcode',
                                        'latitude'          => 'hou_latitude',
                                        'longitude'         => 'hou_longitude',
                                        'amount_person'     => 'hou_amount_person'

    );
    $pntable['votecanvasser_house_no_column_def'] = array(
                                        'id'                => 'BIGINT(255) NOTNULL AUTOINCREMENT PRIMARY',
                                        'pro_id'            => 'INT(11) NOTNULL',   
                                        'dis_id'            => 'INT(11) NOTNULL',  
                                        'tam_id'            => 'INT(11) NOTNULL',
                                        'vil_id'            => 'INT(11) NOTNULL',
                                        'vil_moo'           => 'INT(11) NOTNULL',
                                        'no'                => 'varchar(50)',
                                        'unit'              => 'INT(11) NOTNULL',
                                        'trok'              => 'INT(11) ',
                                        'soi'               => 'VARCHAR(255)',
                                        'road'              => 'VARCHAR(255)',
                                        'zipcode'           => 'INT(11) ',
                                        'latitude'          => 'varchar(255)',
                                        'longitude'         => 'varchar(255)',
                                        'amount_person'     => 'INT(11) NOTNULL DEFAULT 0'
    );
    $pntable['votecanvasser_house_no_primary_key_column'] = 'id';

    // add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['votecanvasser_house_no_column'], 'hou_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['votecanvasser_house_no_column_def']);

    $pntable['votecanvasser_house_no_column_idx'] = array(
                                                           'idx_hou_pro_id' => 'pro_id',
                                                           'idx_hou_dis_id' => 'dis_id',
                                                           'idx_hou_tam_id' => 'tam_id',
                                                           'idx_hou_id'     => 'vil_id',
                                                           'idx_hou_moo'    => 'vil_moo',
    );


    ////////////////////////////////////////////
    //Canvasser person table  
    ////////////////////////////////////////////
    $pntable['votecanvasser_person'] = DBUtil::getLimitedTablename('votecanvasser_person');
    $pntable['votecanvasser_person_column'] = array(
                                        'id'                => 'per_id',
                                        'pro_id'            => 'per_pro_id',
                                        'dis_id'            => 'per_dis_id',
                                        'tam_id'            => 'per_tam_id',
                                        'vil_id'            => 'per_vil_id',
                                        'hou_id'            => 'per_hou_id',
                                        'per_id'            => 'per_per_id',
                                        'pid'               => 'per_pid',
                                        'gen_id'            => 'per_gen_id',
                                        'typ_id'            => 'per_typ_id',
                                        'titlename'         => 'per_titlename',
                                        'firstname'         => 'per_firstname',
                                        'lastname'          => 'per_lastname',
                                        'telephone'         => 'per_telephone',
                                        'status'            => 'per_status'
    );

    $pntable['votecanvasser_person_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'pro_id'            => 'INT(11) NOTNULL',   
                                        'dis_id'            => 'INT(11) NOTNULL',  
                                        'tam_id'            => 'INT(11) NOTNULL',
                                        'vil_id'            => 'INT(11) NOTNULL',
                                        'hou_id'            => 'INT(11) NOTNULL',
                                        'per_id'            => 'INT(11) NOTNULL',
                                        'pid'               => 'VARCHAR(255)',
                                        'gen_id'            => 'INT(11) NOTNULL',
                                        'typ_id'            => 'INT(11) NOTNULL',
                                        'titlename'         => 'VARCHAR(255)',
                                        'firstname'         => 'VARCHAR(255)',
                                        'lastname'          => 'VARCHAR(255)',
                                        'telephone'         => 'VARCHAR(255)',
                                        'status'            => 'INT(11) NOTNULL'
    );
    $pntable['votecanvasser_person_primary_key_column'] = 'id';
    
    //Add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['votecanvasser_person_column'], 'per_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['votecanvasser_person_column_def']);


    ////////////////////////////////////////////
    //Meeting table
    ////////////////////////////////////////////
    $pntable['votecanvasser_meeting'] = DBUtil::getLimitedTablename('votecanvasser_meeting');
    $pntable['votecanvasser_meeting_column'] = array(
                                        'id'                => 'mee_id',
                                        'date'              => 'mee_name'
    );
    $pntable['votecanvasser_meeting_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'date'              => 'DATE'
    );
    $pntable['votecanvasser_meeting_primary_key_column'] = 'id';
    
    //Add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['votecanvasser_meeting_column'], 'mee_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['votecanvasser_meeting_column_def']);


    ////////////////////////////////////////////
    //Person Meeting table
    ////////////////////////////////////////////
    $pntable['votecanvasser_person_meeting'] = DBUtil::getLimitedTablename('votecanvasser_person_meeting');
    $pntable['votecanvasser_person_meeting_column'] = array(
                                        'id'            => 'cam_id',
                                        'per_id'        => 'cam_per_id',
                                        'mee_id'        => 'cam_mee_id'
    );
    $pntable['votecanvasser_person_meeting_column_def'] = array(
                                        'id'            => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'per_id'        => 'INT(11) NOTNULL',
                                        'mee_id'        => 'INT(11) NOTNULL'
    );
    $pntable['votecanvasser_person_meeting_primary_key_column'] = 'id';
    
    //Add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['votecanvasser_person_meeting_column'], 'cam_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['votecanvasser_person_meeting_column_def']);


    ////////////////////////////////////////////
    //Person Type table
    ////////////////////////////////////////////
    $pntable['votecanvasser_person_type'] = DBUtil::getLimitedTablename('votecanvasser_person_type');
    $pntable['votecanvasser_person_type_column'] = array(
                                        'id'             => 'cat_id',
                                        'per_id'         => 'cat_per_id',
                                        'typ_id'         => 'cat_typ_id'
    );
    $pntable['votecanvasser_person_type_column_def'] = array(
                                        'id'             => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'per_id'         => 'INT(11) NOTNULL',
                                        'typ_id'         => 'INT(11) NOTNULL'
    );
    $pntable['votecanvasser_person_type_primary_key_column'] = 'id';
    
    //Add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['votecanvasser_person_type_column'], 'cat_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['votecanvasser_person_type_column_def']);


    return $pntable;
}